/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import com.sun.faces.facelets.tag.jsf.core.ConvertDateTimeHandler;
import entity.Recetas;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author FRANCO
 * @author alberto
 */
@Stateless
public class RecetasFacade extends AbstractFacade<Recetas> implements RecetasFacadeRemote {
    @PersistenceContext(unitName = "socafe-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public RecetasFacade() {
        super(Recetas.class);
    }

    @Override
    public boolean crearReceta(String preparacion) {
        Recetas receta = new Recetas(Integer.MIN_VALUE);
        receta.setModoPreparacion(preparacion);
        
        try{
            create(receta);
            return true;
        }catch(Exception ex){ 
            return false;
        }  
        
    }

    @Override
    public int getLastInsert() {
        
        int lastId =  Integer.parseInt(getEntityManager().createNativeQuery("SELECT LAST_INSERT_ID()").getSingleResult().toString());
        return lastId;
    }
    
    
    
}
